<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>MoYu--首页</title>

  <link rel="shortcut icon" th:href="@{/imgs/favicon.ico}" href="favicon.ico"/>
  <link href="https://cdn.bootcss.com/twitter-bootstrap/3.3.6/css/bootstrap.css" rel="stylesheet">
  <link href="https://cdn.bootcss.com/bootstrap-treeview/1.2.0/bootstrap-treeview.min.css" rel="stylesheet">
</head>

<body class="gray-bg">
<div class="row">
  <hr>
  <h2>Checkable Tree</h2>
  <div class="col-sm-4">
    <h2>Input</h2>
    <div class="form-group">
      <label for="input-check-node" class="sr-only">Search Tree:</label>
      <input type="input" class="form-control" id="input-check-node" placeholder="Identify node..." value="Parent 1">
    </div>
    <div class="checkbox">
      <label>
        <input type="checkbox" class="checkbox" id="chk-check-silent" value="false">
        Silent (No events)
      </label>
    </div>
    <div class="form-group row">
      <div class="col-sm-6">
        <button type="button" class="btn btn-success check-node" id="btn-check-node">Check Node</button>
      </div>
    </div>
    <div class="form-group">
      <button type="button" class="btn btn-danger check-node" id="btn-uncheck-node">Uncheck Node</button>
    </div>
    <div class="form-group">
      <button type="button" class="btn btn-primary check-node" id="btn-toggle-checked">Toggle Node</button>
    </div>
    <hr>
    <div class="form-group row">
      <div class="col-sm-6">
        <button type="button" class="btn btn-success" id="btn-check-all">Check All</button>
      </div>
    </div>
    <button type="button" class="btn btn-danger" id="btn-uncheck-all">Uncheck All</button>
  </div>
  <div class="col-sm-4">
    <h2>Tree</h2>
    <div id="treeview-checkable" class=""></div>
  </div>
  <div class="col-sm-4">
    <h2>Events</h2>
    <div id="checkable-output"></div>
  </div>
</div>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script src="https://cdn.bootcss.com/bootstrap-treeview/1.2.0/bootstrap-treeview.min.js"></script>
</body>
<script type="text/javascript">
  var defaultData = [
    {
      text: 'Parent 1',
      href: '#parent1',
      tags: ['4'],
      nodes: [
        {
          text: 'Child 1',
          href: '#child1',
          tags: ['2'],
          state:{
            expanded:true
          },
          nodes: [
            {
              text: 'Grandchild 1',
              href: '#grandchild1',
              tags: ['1'],
              state:{
                checked:true,

              }
            },
            {
              text: 'Grandchild 2',
              href: '#grandchild2',
              tags: ['1']
            }
          ]
        },
        {
          text: 'Child 2',
          href: '#child2',
          tags: ['0']
        }
      ]
    },
    {
      text: 'Parent 2',
      href: '#parent2',
      tags: ['0']
    },
    {
      text: 'Parent 3',
      href: '#parent3',
      tags: ['0']
    },
    {
      text: 'Parent 4',
      href: '#parent4',
      tags: ['0']
    },
    {
      text: 'Parent 5',
      href: '#parent5',
      tags: ['0']
    }
  ];
  var $checkableTree = $('#treeview-checkable').treeview({
    data: defaultData,
    showIcon: false,
    showCheckbox: true,
    onNodeChecked: function (event, node) {
      $('#checkable-output').prepend('<p>' + node.text + ' was checked</p>');
    },
    onNodeUnchecked: function (event, node) {
      $('#checkable-output').prepend('<p>' + node.text + ' was unchecked</p>');
    }
  });
  var findCheckableNodess = function () {
    return $checkableTree.treeview('search', [$('#input-check-node').val(), {ignoreCase: false, exactMatch: false}]);
  };
  var checkableNodes = findCheckableNodess();

  // Check/uncheck/toggle nodes
  $('#input-check-node').on('keyup', function (e) {
    checkableNodes = findCheckableNodess();
    $('.check-node').prop('disabled', !(checkableNodes.length >= 1));
  });

  $('#btn-check-node.check-node').on('click', function (e) {
    $checkableTree.treeview('checkNode', [checkableNodes, {silent: $('#chk-check-silent').is(':checked')}]);
  });

  $('#btn-uncheck-node.check-node').on('click', function (e) {
    $checkableTree.treeview('uncheckNode', [checkableNodes, {silent: $('#chk-check-silent').is(':checked')}]);
  });

  $('#btn-toggle-checked.check-node').on('click', function (e) {
    $checkableTree.treeview('toggleNodeChecked', [checkableNodes, {silent: $('#chk-check-silent').is(':checked')}]);
  });

  // Check/uncheck all
  $('#btn-check-all').on('click', function (e) {
    $checkableTree.treeview('checkAll', {silent: $('#chk-check-silent').is(':checked')});
  });

  $('#btn-uncheck-all').on('click', function (e) {
    $checkableTree.treeview('uncheckAll', {silent: $('#chk-check-silent').is(':checked')});
  });
</script>
</html>